package gui;

import java.awt.Component;
import java.awt.Graphics;
import java.util.LinkedList;

import test.Polygon;

@SuppressWarnings("serial")
public class PolygonCanvas extends Component {

	private LinkedList<Polygon> list;

	public PolygonCanvas(LinkedList<Polygon> list) {
		this.list = list;
	}

	public synchronized void addPolygon(Polygon p) {
		list.add(p);
	}

	public synchronized void clear() {
		list.clear();
	}

	@Override
	public synchronized void paint(Graphics g) {
		for (Polygon p : list) {
			g.setColor(p.getColor());
			g.fillPolygon(p.getXArray(), p.getYArray(), p.getV().size());
		}
	}

	public synchronized void setList(LinkedList<Polygon> list) {
		this.list = list;
	}

	@Override
	public String toString() {
		return list.toString();
	}

}
